#this program gets the coordinates of the polygon vertices that make up the contours and prints them #to a text file for import into Mathematica import os #imports the operating system module, needed for file and directory functions import numpy as np #imports the NumPy scientific computing library and makes np shorthand for numpy os.chdir("/Users/Documents/pydicom-0.9.7") #sets the directory path import dicom #imports the pydicom package #the line below reads in the DICOM RTStruct file and names it rtstructfile rtstructfile=dicom.read_file("structure set.dcm") num_contourslices=len(rtstructfile.ROIContours[0].Contours) #gets the number of contour slices textfile=open("contour_slice_data_for_Mathematica.txt","w") #creates a text file in write mode #the for loop below obtains the coordinates of the contour vertices for each slice of the dataset for contour_slicenumber in range(0,num_contourslices): contour_slice_data=rtstructfile.ROIContours[0].Contours[contour_slicenumber].ContourData textfile=open("contour_slice_data_for_Mathematica.txt","a") #opens the text file in append mode print >>textfile, contour_slice_data #writes the contour vertices coordinates to the text file textfile.close() #closes the text file